﻿using CKS.Core.Framework;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ZR.Model.Enum;
using ZR.Model.Models.ProductionControl;

namespace CKS.PLC.Action.Subscription.OP20
{
    /*
     * 定位柱上料请求
     * 
     */
    public class DB3031_Work03Action : PLCAction
    {

        public DB3031_Work03Action(DecodeValue _value) : base(_value)
        {
        }
        public override void Execute()
        {
            var replyPos = Value.GetPosition(3050, 30);
            var result = Value.Value.ToInt();
            string batchNo = GetPartBatchNo((int)PartTypeEnum.定位柱);
            if (result == 1)
            {
                //更新定位柱剩余零件数量
                string blueCode = Value.GetLinkData(1).ToString();
                int count = Value.GetLinkData(2).ToInt();
                UpdateBasketStock(blueCode, count);
                AckWriteInt16(replyPos, 1);
                EventBus.AddLog($"OP20抓取定位柱,子篮{blueCode}剩余数量{count}");
            }
            else
            {
                AckWriteInt16(replyPos, 0);
                EventBus.AddLog("OP20抓取定位柱状态重置");
            }
        }
    }
}
